package com.xcc.shopanim.mode;

import java.util.ArrayList;
import java.util.List;

public class MainLiveVideoGroupMode {
    public List<NewMainVideoMode> appLiveBanners;//置顶
    public List<BannerMode> homePageBanners;//banner
    public List<NewMainVideoMode> feedSelectRecommends;

    private transient List<NewMainVideoMode> videoModeList;
    public transient int skipPos;//跳转目标的位置

    public void initGroup() {//新需求要求顺序 回放>定位到置顶坑位中>直播中>banner>预告>
        if (videoModeList == null) {
            videoModeList = new ArrayList<>();

            if (appLiveBanners == null) appLiveBanners = new ArrayList<>();
            if (homePageBanners == null) homePageBanners = new ArrayList<>();
            if (feedSelectRecommends == null) feedSelectRecommends = new ArrayList<>();

            List<NewMainVideoMode> list = new ArrayList<>(feedSelectRecommends);
            //查找回放
            for (int i = 0; i < list.size(); i++) {
                NewMainVideoMode videoMode = list.get(i);
                if (videoMode.contentType == 4 || videoMode.contentType == -1) {
                    videoModeList.add(videoMode);
                    list.remove(i);
                    i--;
                }
            }
            //设置位置
            skipPos = videoModeList.size();
            //添加置顶appLiveBanners
            videoModeList.addAll(appLiveBanners);
            //查找直播中
            for (int i = 0; i < list.size(); i++) {
                NewMainVideoMode videoMode = list.get(i);
                if (videoMode.contentType == 1) {
                    videoModeList.add(videoMode);
                    list.remove(i);
                    i--;
                }
            }
            //添加banner
            for (int i = 0; i < homePageBanners.size(); i++) {
                BannerMode bannerMode = homePageBanners.get(i);

                NewMainVideoMode videoMode = new NewMainVideoMode();
                videoMode.bannerMode = bannerMode;
                videoMode.contentType = -3;
                videoModeList.add(videoMode);
            }
            //添加预告
            for (int i = 0; i < list.size(); i++) {
                NewMainVideoMode videoMode = list.get(i);
                if (videoMode.contentType == 5 || videoMode.contentType == -2) {
                    videoModeList.add(videoMode);
                }
            }
            //最后验证skipPos
            if (skipPos > 0 && skipPos == videoModeList.size()) {
                skipPos = videoModeList.size() - 1;
            }
        }
    }

    public List<NewMainVideoMode> getVideoModeList() {
        initGroup();
        return videoModeList;
    }
}
